package bookExercise;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class A16distinct {
    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(4);
        list.add(8);
        list.add(4);
        list.add(6);
        list.add(3);
        list.add(1);
        printeach("原来的集合：",list);
        Stream<Integer> stream = list.stream();
        stream =stream.distinct();
        List<Integer> collect = stream.collect(Collectors.toList());
        printeach("去除重复元素后:",collect);

    }
    public static void printeach(String message,List list){
        System.out.print(message);
        for (Object o : list) {
            System.out.print(o+" ");
        }
        System.out.println();
    }
}
